package main

import (
	"fmt"
	"github.com/gogf/gf/os/gtimer"
	"github.com/gogf/gf/util/gconv"
	"github.com/gogf/gf/util/grand"
	_ "origin/initFunc"
	"origin/test"
	"os"
	"os/signal"
	"strings"
	"syscall"
	"time"
)

func do(b *strings.Builder) {
	b.WriteString(gconv.String(grand.N(0, 1)))
}

var a strings.Builder

func main() {

	url := "Aaaaaa"
	for i := 0; i < 3; i++ {
		//url += "&" + "ascas"
		url = url + "&" + "ascas"
	}
	fmt.Println(url)

	var buf strings.Builder
	for i := 0; i < 10; i++ {
		buf.WriteString(`{"abc":"bcd"},`) // 使用 strings.Builder 优化拼接
	}
	fmt.Println(buf.String())

	gtimer.AddSingleton(1000*time.Millisecond, func() {
		do(&a)
		fmt.Println(a.String())
	})

	//服务路由注册、定义
	test.HttpServerRun()
	//做一个管道堵塞住服务，使服务可以一直运行，并且捕获信号，做退出操作
	quit := make(chan os.Signal)
	signal.Notify(quit, syscall.SIGKILL, syscall.SIGQUIT, syscall.SIGINT, syscall.SIGTERM)
	<-quit

	test.HttpServerStop()
}
